package com.fizz.config;


import com.fizz.common.DataSourceTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DatasourceContextHolder {

    private static Logger logger = LoggerFactory.getLogger(DatasourceContextHolder.class);

    private static final ThreadLocal<String> local = new ThreadLocal<String>();

    public static void setRead(){
        local.set(DataSourceTypeEnum.READ_DATA_SOURCE.type);
        logger.info("数据库切换到读库");

    }

    public static void setWrite(){
        local.set(DataSourceTypeEnum.WRITE_DATA_SOURCE.type);
        logger.info("数据库切换到写库");
    }

    public static String getReadOrWrite(){
        return local.get();
    }

}
